package com.xiaozhu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.xiaozhu.dao.BookDao;
import com.xiaozhu.domin.Book;
import com.xiaozhu.service.BookService;
import org.apache.logging.log4j.util.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class BookServiceImpl extends ServiceImpl<BookDao,Book> implements BookService {
    @Autowired
    private BookDao bookDao;
//    @Override
//    public Boolean save(Book book) {
//        return  bookDao.insert(book)>0;
//    }
//
//    @Override
//    public Boolean delete(Integer id) {
//        return bookDao.deleteById(id)>0;
//    }
//
//    @Override
//    public Boolean update(Book book) {
//        return bookDao.updateById(book)>0;
//    }
//
//    @Override
//    public Book getById(Integer id) {
//        return bookDao.selectById(id);
//    }
//
//    @Override
//    public List<Book> selectAll() {
//        return bookDao.selectList(null);
//    }
//
    @Override
    public IPage<Book> getByPage(int currentPage, int pageSize) {
        IPage page=new Page(currentPage,pageSize);
        bookDao.selectPage(page,null);
        return page;
    }
    @Override
    public IPage<Book> getByPage(int currentPage, int pageSize, Book book) {
        LambdaQueryWrapper<Book> bookLambdaQueryWrapper = new LambdaQueryWrapper<Book>();
        bookLambdaQueryWrapper.like(Strings.isNotEmpty(book.getType()),Book::getType,book.getType());
        bookLambdaQueryWrapper.like(Strings.isNotEmpty(book.getName()),Book::getName,book.getName());
        bookLambdaQueryWrapper.like(Strings.isNotEmpty(book.getDescription()),Book::getDescription,book.getDescription());
        IPage page=new Page(currentPage,pageSize);
        bookDao.selectPage(page,bookLambdaQueryWrapper);
        return page;
    }
}
